package com.fighYo.trace.oss.controller;

import com.fighYo.trace.oss.service.OssService;
import com.fighYo.trace.utils.OssUtil;
import com.fighYo.trace.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = {"OSS文件管理"})
@RestController
@Slf4j
@RequestMapping("/oss")
@CrossOrigin
public class OssController {

//    @Autowired
//    private OssService ossService;

    @Autowired
    private OssUtil ossUtil;

    @ApiOperation("上传")
    @PostMapping("upload")
    public R uploadOssAvatar(MultipartFile file) {
        String url = ossUtil.uploadFile(file);
        log.info("上传文件成功 url: {}", url);
        return R.ok().data("url", url);
    }

}
